<?php
class database{
	public $connection;

	public function __construct($dbhost, $dbuser, $dbpass, $dbname){
		$this->connection = mysql_connect($dbhost, $dbuser, $dbpass);
		if($this->connection){
			$db = mysql_select_db($dbname, $this->connection);
			if(!$db){
				print "Error: DATABASE";
				exit;
			}
		}
		else{
			print "Error: DATABASE SERVER";
			exit;
		}
	}

	public function getTartalom($link){
		$sql = "SELECT id, cim, szoveg, szulo FROM tartalom WHERE link='".$link."'";
		$result = mysql_query($sql);
		$cnt = mysql_num_rows($result);
		if($cnt>0){
			$return = mysql_fetch_row($result);
			return $return;
		}
		else{
			return null;
		}
	}

	public function getKapcsolat(){
		$sql = "SELECT cim, szoveg FROM tartalom WHERE link='arajanlat'";
		$result = mysql_query($sql, $this->connection);
		$return = mysql_fetch_row($result);
		return $return;
	}

	public function createMenu($link){
		$sql = "SELECT id, cim, link, szulo FROM tartalom WHERE statusz > 0";
		$result = mysql_query($sql, $this->connection);
		$cnt = mysql_num_rows($result);
		if($cnt>0){
			$return = new menu();
			while($row = @mysql_fetch_row($result)){
				$content = "tartalom/";
				//if($row[2]=="arajanlat"){ $content=""; } erre nincs szükség mert adatbázisból kérjük le a kapcsolatot is
				$return->addItem($row[0], $row[1], $link.$content.$row[2], $row[3]);
			}
			return $return;
		}
		else{
			return null;
		}

	}

	public function close(){
		mysql_close($this->connection);
	}
}
?>